package cn.com.SpringBoot.controller;

import cn.com.SpringBoot.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @Autowired
    private Environment environment;
    @Autowired
    UserInfo userInfo;

    @Value("${user.phone}")
    private String phone;

    @Value("${user.username}")
    private String username;

    @Value("${booksTwo[0].name}")
    private String BooksName;

    @GetMapping("/hello")
    public String hello(){
        return "hello SpringBoot";
    }

    @GetMapping("/user")
    public String user() {
        return "hello "+username+" 我的电话是:"+phone;
    }

    @GetMapping("/book")
    public String book(){
        return "书名:"+BooksName;
    }

    @GetMapping("/userInfo")
    public String userInfo() {
        System.out.println("username:"+environment.getProperty("username"));
        System.out.println("password:"+environment.getProperty("password"));
        return "输出本机电脑数据";
    }

    @GetMapping("/userInfoTwo")
    public String userInfoTwo() {
        System.out.println(userInfo);
        return "输出实体类数据";
    }
}